import request from "./request";

export function login(query) {
  return request({
    url: "/user/login",
    method: "post",
    data: query,
  });
}

export function register(query) {
  return request({
    url: "/user/register",
    method: "post",
    data: query,
  });
}

export function logout(token) {
  return request({
    url: "/user/logout",
    method: "post",
    headers: {
      Authorization: `${token}`,
    },
  });
}

export function userInfo(token) {  
  return request({  
    url: "/user/info",  
    method: "get",  
    headers: {  
      Authorization: `${token}`, // 通常Authorization头部会包含一个前缀，如，后跟令牌  
    },  
  });  
}



export function updateUserStatus(username, status, token) {
  return request({
    url: `/user/updateStatus/${username}`,
    method: 'patch',
    params: { status },
    headers: {
      Authorization: `${token}`,
    },
  });
}

//写一个获取所有用户的方法
export function getAllUser(token) {
  return request({
    url: "/user/users",
    method: "get",
    headers: {
      Authorization: `${token}`, // 将 token  令牌发送
    },
  });
}
//删除用户
export function deleteUser(id, token) {
  return request({
    url: "/user/delete/" + id,
    method: "delete",
    headers: {
      Authorization: `${token}`, // 将 token  令牌发送
    },
  });
}

//修改密码
export function updatePassword(query, token) {
  return request({
    url: "/user/changePassword",
    method: "post",
    data: query,
    headers: {
      Authorization: `${token}`, // 将 token  令牌发送
    },
  });
}

export function onlineUsers() {
  return request({
    url: "/user/onlineUsers",
    method: "get",
  });
}




// 发送验证码
// export function sendCode(email) {
//   return request({
//     url: "/demo/user/sendCode",
//     method: "post",
//     params: email,
//   });
// }

// 验证验证码
// export function verifyCode(query) {
//   return request({
//     url: "/demo/user/verifyCode",
//     method: "post",
//     params: query,
//   });
// }
